<template>
  <view class="page">
    <view class="search-bar">
      <view class="search-input">
        <input type="text" v-model="query.keywords" placeholder="请输入姓名/学号/学院名" />
        <image class="icon-search" src="/static/images/icon_search.png" mode=""></image>
        <view class="search-button" @click="search">搜索</view>
      </view>
    </view>
    <view class="input-bar">
      <view class="input-item">
        <input type="text" v-model="query.assistant" placeholder="谈话辅导员" />
      </view>
      <view class="input-item">
        <input type="text" v-model="query.minTalkCnt" placeholder="最小值谈话次数" />
      </view>
      <view class="input-meta">~</view>
      <view class="input-item">
        <input type="text" v-model="query.maxTalkCnt" placeholder="最大值谈话次数" />
      </view>
    </view>
    <u-dropdown class="dropdown" :activeColor="dropdown.activeColor" :borderBottom="dropdown.borderBottom"
      :close-on-click-mask="dropdown.mask" ref="uDropdown">
      <u-dropdown-item @change="personTypeChange" v-model="query.personType" :title="dropdown.personTypeTitle"
        :options="dropdown.personTypeOption"></u-dropdown-item>
      <u-dropdown-item @change="zydmChange" v-model="query.zydm" :title="dropdown.zydmTitle"
        :options="dropdown.zydmOption"></u-dropdown-item>
      <u-dropdown-item @change="isNeedTalkChange" v-model="query.isNeedTalk" :title="dropdown.isNeedTalkTitle"
        :options="dropdown.isNeedTalkOption"></u-dropdown-item>
    </u-dropdown>
    <!-- <view class="search">
      <u-search v-model="query.keywords" @custom="search" @search="search" height="80"
        placeholder="请输入姓名/学号/学院名"></u-search>
      <u-row gutter="16" style="margin-top: 10rpx;">
        <u-col span="5">
          <u-input v-model="query.assistant" :height="60" type="input" :border="true" placeholder="谈话辅导员" />
        </u-col>
        <u-col span="3">
          <u-input v-model="query.minTalkCnt" :height="60" type="input" :border="true" placeholder="最小值谈话次数" />
        </u-col>
        ~
        <u-col span="3">
          <u-input v-model="query.maxTalkCnt" :height="60" type="input" :border="true" placeholder="最大值谈话次数" />
        </u-col>
      </u-row>
    </view> -->
    <scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore">
      <view class="card-list">
        <view v-for="(item, index) in list" :key="index" class="card-item" @click="handleClick(item)">
          <view class="card-item-hd">{{item.deptName}}</view>
          <view class="card-item-bd">
            <view class="card-title">{{item.realName}}({{item.account}})</view>
            <view class="card-desc">{{item.sexName}} | 谈话次数({{item.talkCnt}})</view>
          </view>
          <view v-if="hasPermission('misAssistantUserExt_edit')" class="edit">编辑</view>
        </view>
      </view>
      <!-- <view class="uni-list" v-for="(item, index) in list" :key="index" style="margin-top: 5rpx;margin-bottom: 5rpx;"
        @click="handleClick(item)">
        <u-row gutter="16" style="margin-top: 20rpx;">
          <u-col span="7"
            style="word-break:break-all;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-weight:bold">
            {{item.realName}}({{item.account}})
          </u-col>
          <u-col span="5" style="text-align: right;">
            <view style="text-align: right;color: gray;margin-right: 10rpx;">
              {{item.deptName}}
            </view>
          </u-col>
        </u-row>
        <u-row gutter="16" style="margin-top: 20rpx;margin-bottom: 10rpx;">
          <u-col span="6">
            <view style="text-align: left;color: gray;">
              {{item.sexName}} | 谈话次数({{item.talkCnt}})
            </view>
          </u-col>
          <u-col span="6" style="text-align: right;">
            <u-button size="mini" shape="circle" plain type="primary" @click="handleClick(item)"
              v-if="hasPermission('misAssistantUserExt_edit')">编辑</u-button>
          </u-col>
        </u-row>
      </view> -->
      <u-loadmore class="loadmore" :status="loadStatus"></u-loadmore>
    </scroll-view>
  </view>
</template>
<script>
  import $time from '@/common/time.js';
  export default {
    data() {
      return {
        query: {
          current: 1,
          size: 10,
          keywords: '',
          talkBeginDate: '',
          talkBeginDate: '',
          personType: '',
          zydm: '',
          isNeedTalk: '',
          createUser: ''
        },
        list: [],
        pages: 0,
        loadStatus: 'loadmore',
        options: [],
        headStyle: {
          fontWeight: 'bold',
          color: '#606266',
          margin: '16rpx'
        },
        statusList: [],
        swiperCurrent: 0,
        dropdown: {
          borderBottom: false,
          activeColor: '#2979ff',
          mask: true,
          personTypeOption: [],
          personTypeTitle: '用户类型',
          zydmOption: [],
          zydmTitle: '专业',
          isNeedTalkOption: [],
          isNeedTalkTitle: '必谈对象',
        },
      };
    },
    onLoad(params) {
      if (params.createUser) {
        this.query.createUser = params.createUser;
      }
      this.loadList();
      this.initIsNeedTalk();
      this.initZydm();
      this.initPersonType();
    },
    computed: {

    },
    methods: {
      navTo(url) {
        uni.navigateTo({
          url: url
        });
      },
      search(value) {
        this.list = [];
        this.query.current = 0;
        this.loadList();
      },
      loadList() {
        this.$u.api.mis.misAssistantUserExt.list(this.query).then(res => {
          if (!res.data.records || res.data.records.length == 0) {
            this.loadStatus = "nomore";
            return;
          }
          res.data.records.forEach((item) => {
            item.show = false;
          })
          this.list = this.list.concat(res.data.records);
          this.pages = res.pages;
          this.query.current = res.data.current;
          this.query.size = res.data.size;
          this.loadStatus = "loadmore";
        });
      },
      loadMore() {
        this.loadStatus = "loading";
        setTimeout(() => {
          this.query.current += 1;
          this.loadList();
        }, 100);
      },
      handleClick(row) {
        this.navTo('form?id=' + row.userId);
      },
      initPersonType() {
        this.$u.api.dictData({
          code: 'system_person_type'
        }).then(res => {
          let detaiList = [];
          let detailJson = {
            'label': '全部',
            'value': ''
          }
          detaiList.push(detailJson)
          res.data.forEach((item) => {
            if (item.dictKey !== '1') {
              detaiList.push({
                'label': item.dictValue,
                'value': item.dictKey
              });
            }
          })
          this.dropdown.personTypeOption = detaiList;
        });
      },
      initIsNeedTalk() {
        this.$u.api.dictData({
          code: 'yes_no'
        }).then(res => {
          let detaiList = [];
          let detailJson = {
            'label': '全部',
            'value': ''
          }
          detaiList.push(detailJson)
          res.data.forEach((item) => {
            detaiList.push({
              'label': item.dictValue,
              'value': item.dictKey
            });
          })
          this.dropdown.isNeedTalkOption = detaiList;
        });
      },
      initZydm() {
        this.$u.api.user.getZyDictData({}).then(res => {
          let detaiList = [];
          let detailJson = {
            'label': '全部',
            'value': ''
          }
          detaiList.push(detailJson)
          res.data.forEach((item) => {
            detaiList.push({
              'label': item.zyName,
              'value': item.zyCode
            });
          })
          this.dropdown.zydmOption = detaiList;
        });
      },
      personTypeChange(index) {
        this.list = [];
        this.query.current = 0;
        this.query.personType = index
        this.dropdown.personTypeTitle = (index === '' ? '用户类型' : this.getOptionLabel(this.dropdown.personTypeOption,
          index));
        this.loadList()
      },
      isNeedTalkChange(index) {
        this.list = [];
        this.query.current = 0;
        this.query.isNeedTalk = index
        this.dropdown.isNeedTalkTitle = (index === '' ? '必谈对象' : this.getOptionLabel(this.dropdown.isNeedTalkOption,
          index));
        this.loadList()
      },
      zydmChange(index) {
        this.list = [];
        this.query.current = 0;
        this.query.zydm = index
        this.dropdown.zydmTitle = (index === '' ? '专业' : this.getOptionLabel(this.dropdown.zydmOption, index));
        this.loadList()
      },
    }
  };
</script>
<style lang="scss">
  .page {
    position: relative;
    background: #F7F7F7;
  }

  .search-bar {
    display: flex;
    align-items: center;
    padding: 16rpx 32rpx;
    background: #fff;
  }

  .search-input {
    position: relative;
    width: 100%;
    height: 64rpx;
    border-radius: 32rpx;
    background: #F7F7F7;
    overflow: hidden;

    input {
      width: 100%;
      height: 64rpx;
      border: 0;
      padding: 0 144rpx 0 64rpx;
      outline: 0;
      line-height: 64rpx;
      font-size: 24rpx;
      font-weight: 500;
      color: #999;
      background: transparent;
    }

    .icon-search {
      position: absolute;
      top: 21rpx;
      left: 21rpx;
      width: 22rpx;
      height: 22rpx;
    }

    .search-button {
      position: absolute;
      top: 0;
      right: 0;
      width: 144rpx;
      border-radius: 32rpx;
      line-height: 64rpx;
      text-align: center;
      font-size: 24rpx;
      font-weight: 700;
      color: #fff;
      background: #3989FC;
    }
  }

  .input-bar {
    display: flex;
    align-items: center;
    padding: 8rpx 32rpx;
    background: #fff;
  }

  .input-item {
    width: 220rpx;

    &+.input-item {
      margin-left: 16rpx;
    }

    input {
      width: 100%;
      height: 64rpx;
      border: 1px solid #eee;
      border-radius: 8rpx;
      padding: 0 16rpx;
      outline: 0;
      line-height: 64rpx;
      font-size: 28rpx;
      font-weight: 500;
      color: #999;
      background: transparent;
    }
  }
  
  .input-meta {
    margin: 0 16rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: #999;
  }

  .dropdown {
    height: 80rpx;
    background: #fff;

    &+.scroll-list {
      height: calc(100vh - var(--window-top) - var(--window-bottom) - 96rpx - 80rpx - 80rpx);
    }
  }

  .scroll-list {
    height: calc(100vh - var(--window-top) - var(--window-bottom) - 96rpx);

    .loadmore {
      padding: 32rpx;
    }
  }

  .card-list {
    display: flex;
    flex-direction: column;
    padding: 24rpx 24rpx 0;
  }

  .card-item {
    position: relative;
    border-radius: 8rpx;
    padding: 32rpx;
    margin-bottom: 24rpx;
    background: #fff;

    .edit {
      position: absolute;
      top: 32rpx;
      right: 32rpx;
      display: inline-block;
      border-radius: 56rpx;
      padding: 0 24rpx;
      line-height: 56rpx;
      font-size: 24rpx;
      color: #fff;
      background: #005EFF;
    }
  }

  .card-item-hd {
    margin-bottom: 24rpx;
    font-size: 28rpx;
    font-weight: 500;
    color: #666;
  }

  .card-title {
    margin-bottom: 16rpx;
    font-size: 32rpx;
    font-weight: 700;
    color: #333;
  }

  .card-desc {
    font-size: 28rpx;
    font-weight: 500;
    color: #999;
  }
</style>